package com.caregiver.watch.business.user.controller;

import com.caregiver.watch.business.user.model.dto.ChatMessage;
import com.caregiver.watch.business.user.model.dto.ReadMessageParam;
import com.caregiver.watch.business.user.model.vo.ChatMessageVo;
import com.caregiver.watch.business.user.model.vo.ChatWindowVo;
import com.caregiver.watch.business.user.service.ChatService;
import com.caregiver.watch.common.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 聊天服务控制器
 * @Author 疆戟
 * @Date 2025/8/30 8:48
 * @Version 1.0
 */
@Tag(name  = "ChatController", description = "聊天服务")
@RestController
@RequestMapping("chat")
public class ChatController {


    @Autowired
    private ChatService chatService;

    @Operation(summary = "查询聊天列表", description = "查询聊天列表")
    @PostMapping("queryChatWindowList")
    public R<List<ChatWindowVo>> queryChatList(@RequestBody List<Long> recipientIds) {
        return R.ok(chatService.queryChatWindowList(recipientIds));
    }


    @Operation(summary = "查询消息列表", description = "查询消息列表")
    @GetMapping("queryMessageList")
    public R<List<ChatMessageVo>> queryMessageList(@RequestParam("chatWindowId") Long chatWindowId,
                                                   @RequestParam("pageNum") Integer pageNum,
                                                   @RequestParam("pageSize") Integer pageSize) {
        return R.ok(chatService.queryMessageList(chatWindowId, pageNum, pageSize));
    }

    @Operation(summary = "发送消息", description = "发送消息")
    @PostMapping("sendMessage")
    public R<Boolean> sendMessage(@RequestBody ChatMessage message) {
        return R.ok(chatService.sendMessage(message));
    }

    @Operation(summary = "清空消息", description = "清空消息")
    @PostMapping("clearMessage")
    public R<Boolean> clearMessage(@RequestBody Long chatWindowId) {
        return R.ok(chatService.clearMessage(chatWindowId));
    }

    @Operation(summary = "读取消息", description = "读取消息")
    @PostMapping("readMessage")
    public R<Boolean> readMessage(@RequestBody ReadMessageParam param) {
        return R.ok(chatService.readMessage(param));
    }

    @Operation(summary = "删除消息", description = "删除消息")
    @PostMapping("deleteMessage")
    public R<Boolean> deleteMessage(@RequestBody List<Long> messageIds) {
        return R.ok(chatService.deleteMessage(messageIds));
    }
}
